<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ include file="common.jsp" %>
<%            // Main Application Logic Comes Here
            ArrayList<Player> players = PlayerDAO.retrieveAllPlayers();
%>

<HTML>
    <c:set var="title" value="MIC Tycoon ~ Admin"/>
    <%@ include file="htmlheader.jsp" %>

    <body>
        <div id="resolution">

            <div class="content" id="admin_content">
                <div id="admin">
                    <img src="<%= realURL("", url)%>images/titles/admin.png" border="0" />
                    <!-- show announcements -->
                    <c:if test="${announcement!=null}">
                        <div id="announcement">
                            <p><c:out value="${announcement}"/></p>
                        </div>
                    </c:if>

                    <div class="admin_panel">
                        <a href="<%=realURL("", url)%>servlet/admin/panel">Refresh Page</a>
                    </div>

                    <c:if test="${turn.current_turn < 0}">
                        <div class="admin_panel">
                            The game has not started, players cannot register
                            <form method="post" action="./startGame">
                                <input type="submit" value="Start Game!">
                            </form>
                        </div>
                    </c:if>

                    <c:if test="${turn.current_turn >= 0}">
                        <div class="admin_panel">
                            Click to restart entire game.
                            <form method="post" action="./reStartGame" onSubmit="return confirm('Restart game?')">
                                <input type="submit" value="Restart Game!">
                            </form>
                        </div>

                        <div class="admin_panel">
                            Click to end game.
                            <form method="post" action="./endGame" onSubmit="return confirm('End game?')">
                                <input type="submit" value="End Game!">
                            </form>
                        </div>
                    </c:if>

                    <c:if test="${turn.current_turn >= 0}">
                        <div class="admin_panel">
                            Current Turn: ${turn.current_turn}, Time left for the turn: ${turn.countdown_second}
                            <form method="post" action="./nextTurn" onSubmit="return confirm('Go to next turn?')">
                                <input type="submit" value="Next Turn >> ">
                            </form>
                        </div>
                    </c:if>

                    <c:if test="${turn.current_turn >= 0}">
                        <div class="admin_panel">
                            <c:set var="pause_label" value="Running"/>
                            <c:set var="pause_action" value="Pause"/>
                            <c:if test="${turn.game_pause == true}">
                                <c:set var="pause_label" value="Paused"/>
                                <c:set var="pause_action" value="Resume"/>
                            </c:if>

                            Game Status: <b>${pause_label}</b>

                            <form method="post" action="./pauseGame" onSubmit="return confirm('${pause_action} Game?')">
                                <input type="submit" value="${pause_action} Game">
                            </form>
                        </div>
                    </c:if>

                    <div class="admin_panel">
                        <form action="<%= realURL("", url)%>servlet/admin/update_index" method="POST">
                            Current economic index: ${turn.index}
                            Next turn index: <input type="text" name="index" />
                            <input type="submit" value="Update index!" />
                        </form>
                    </div>

                    <c:if test="${turn.current_turn >= 0}">
                        <div class="admin_panel">
                            <p><b>Players Information</b></p>
                            <table class="player_table" cellspacing="0" cellpadding="5">

                                <c:forEach items="${player_list}" var="player">
                                    <tr>
                                        <td class="transaction_title" width="20px" >Id</td>
                                        <td class="transaction_title" width="200px" >Player Name</td>
                                        <td class="transaction_title" width="200px">Company Name</td>
                                        <td class="transaction_title" width="200px">Balance</td>
                                        <td class="transaction_title" width="200px">Track Record Points</td>
                                    </tr>
                                    <tr>
                                        <td class="transaction_value">${player.player_id}</td>
                                        <td class="transaction_value">${player.player_name}</td>
                                        <td class="transaction_value">${player.company_name}</td>
                                        <td class="transaction_value">${player.balance_string}</td>
                                        <td class="transaction_value">${player.track_record_points}</td>
                                    </tr>
                                    <tr>
                                        <td colspan="5">
                                            <p><b>Player Projects:</b></p>
                                            <c:if test="${fn:length(player.player_project) == 0}">
                                                <p> <b> -- Player currently has no project -- </b> </p>
                                            </c:if>
                                            <c:forEach items="${player.player_project}" var="project">
                                                <c:set var="action" value="servlet/admin/project/${project.project_id}/inject"/>
                                                <c:set var="label" value="add project inject"/>
                                                <c:if test="${project.inject.project_id != null}">
                                                    <c:set var="action" value="servlet/admin/project/${project.project_id}/update_inject"/>
                                                    <c:set var="label" value="update project inject"/>
                                                </c:if>
                                                <form action="<%= realURL("", url)%>${action}" method="POST">

                                                    <div id="paper-holder-landscape-small">

                                                        <div id="deadline-holder-landscape">${project.due_turn}</div>

                                                        <div id="paper-content-over-project">
                                                            <c:if test="${project.man_hours_dot_net ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_dot_net !=0}"><div id="manhours-on">${project.man_hours_dot_net}</div></c:if>
                                                            <c:if test="${project.man_hours_c_sharp ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_c_sharp !=0}"><div id="manhours-on">${project.man_hours_c_sharp}</div></c:if>
                                                            <c:if test="${project.man_hours_jsp ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_jsp !=0}"><div id="manhours-on">${project.man_hours_jsp}</div></c:if>
                                                            <c:if test="${project.man_hours_php ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_php !=0}"><div id="manhours-on">${project.man_hours_php}</div></c:if>
                                                            <c:if test="${project.man_hours_ruby ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_ruby !=0}"><div id="manhours-on">${project.man_hours_ruby}</div></c:if>
                                                            <c:if test="${project.man_hours_mysql ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_mysql !=0}"><div id="manhours-on">${project.man_hours_mysql}</div></c:if>
                                                            <c:if test="${project.man_hours_mssql ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_mssql !=0}"><div id="manhours-on">${project.man_hours_mssql}</div></c:if>
                                                            <c:if test="${project.man_hours_oracle ==0}"><div id="manhours-off">&nbsp;</div></c:if>
                                                            <c:if test="${project.man_hours_oracle !=0}"><div id="manhours-on">${project.man_hours_oracle}</div></c:if>
                                                        </div>

                                                        <div id="paper-content-landscape">
                                                            <b>Project </b>[<b>#${project.project_id}</b>] ${project.company.name}
                                                            <br/>
                                                            <b>Payout:</b> ${project.bidded_price_string}

                                                            <br/> <b>Remaining Hours:</b>
                                                            <img src="<%= realURL("", url)%>images/logos/logo-levels-h.png" border="0" />

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours" name="dot_net" value="${project.inject.dot_net}"/>
                                                            </div>

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours" name="c_sharp" value="${project.inject.c_sharp}"/>
                                                            </div>

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours"  name="jsp" value="${project.inject.jsp}"/>
                                                            </div>

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours"  name="php" value="${project.inject.php}"/>
                                                            </div>

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours"  name="ruby" value="${project.inject.ruby}"/>
                                                            </div>

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours"  name="mysql" value="${project.inject.mysql}"/>
                                                            </div>

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours"  name="mssql" value="${project.inject.mssql}"/>
                                                            </div>

                                                            <div id="assign-grid">
                                                                <input type="text" class="enter-hours"  name="oracle" value="${project.inject.oracle}"/>
                                                            </div>

                                                            Price: <input type="text" class="enter-hours" id="price-field"  name="price" value="${project.inject.price}"/>

                                                            <input type="submit" value="${label}"/>
                                                            <c:if test="${project.inject.project_id != null}">
                                                                <a href="<%= realURL("", url)%>servlet/admin/project/${project.project_id}/delete_inject">
                                                                    <input type="button" value="remove inject"/>
                                                                </a>
                                                            </c:if>
                                                        </div>
                                                    </div>
                                                </form>
                                            </c:forEach>
                                            <p></p>
                                        </td>
                                    </tr>

                                </c:forEach>
                            </table>
                        </div>
                    </c:if>


                </div>
            </div>
        </div>
    </BODY>
</HTML>